﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Bank_database_system.业务部
{
    public partial class 输入密码 : Form
    {
        private int totalSeconds; // 总倒计时秒数
        private string thecard;
        public 输入密码(string card)
        {
            thecard = card;
            InitializeComponent();

            // 初始化倒计时秒数
            totalSeconds = 60;
            label1.Text = "操作时限：60秒";
            timer1.Start();
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            // 减少剩余时间
            if (totalSeconds > 0)
            {
                totalSeconds--;
                UpdateLabel1();
            }
            else
            {
                // 倒计时结束
                timer1.Stop();
                MessageBox.Show("输入密码超时！");
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
        }

        
        private void UpdateLabel1()
        {
            // 更新 Label 显示
            label1.Text ="操作时限："+$"{totalSeconds}"+"秒";
        }

        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (textBox5.TextLength == 6)
            {
                if (e.KeyChar != '\b')
                    e.Handled = true;
            }
            else
            {
                if ((e.KeyChar > '9' || e.KeyChar < '0') && e.KeyChar != '\b')
                    e.Handled = true;
            }
        }
    

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            timer1.Stop();
            this.Close();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            int i = AccountCheck.passwordCheck(textBox5.Text, thecard);
            if (i==1)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else if(i==0)
            {
                this.DialogResult = DialogResult.No;
                this.Close();
            }
            else if (i == 2)
            {
                this.DialogResult = DialogResult.Yes;
                this.Close();
            }
        }
    }
}
